package com.pine.app.module.security.core.config;


import com.pine.app.module.security.core.web.IWebFilterDef;
import com.pine.app.module.security.core.web.WebThreadFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import java.util.List;

/**
 * @Description: 过滤链配置
 * @Author: xiaoyuan
 * @Date: 2020/3/25 10:46
 */
@Configuration
public class WebConfig {

    /**
     * 自定义过滤器定义
     */
    @Autowired(required = false)
    private List<IWebFilterDef> filterDefs;

    /**
     * 系统内置filter
     * @return
     */
    @Bean
    public FilterRegistrationBean<WebThreadFilter> filterRegistrationBean(@SuppressWarnings("SpringJavaAutowiringInspection") Environment environment) {
        FilterRegistrationBean<WebThreadFilter> registration = new FilterRegistrationBean<>();
        registration.addUrlPatterns("/*");
//        List<IWebFilterDef>  List = new ArrayList<>();
//        List.add(new IWebFilterDefTest());
        WebThreadFilter filterProxy = new WebThreadFilter(filterDefs);
        filterProxy.setEnvironment(environment);
        registration.setFilter(filterProxy);
        registration.setOrder(SecurityProperties.DEFAULT_FILTER_ORDER - 1);
        return registration;
    }
}
